package com.herench.bunch.exam.agent.impl;

import com.herench.bunch.exam.agent.ExamOperationAgent;
import com.herench.bunch.exam.dao.his.IExamDao;
import com.herench.bunch.exam.dao.turtle.ITurtleExamDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author luoxiaoming on 18-10-16 上午9:59
 * @email luoxiaoming@herench.com
 */


@Component
public class ExamOperationAgentImpl implements ExamOperationAgent {

    @Autowired
    private IExamDao iExamDao;
    @Autowired
    private ITurtleExamDao turtleExamDao;

    @Override
    public void modify(Map<String, Object> params) {
        iExamDao.modify(params);
    }

    @Override
    public void delete(Map<String, Object> params) {
        try{
            iExamDao.delete(params);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public Map<String,Object> bill(Map<String, Object> params) {
        params.put("CMZH","");
        params.put("CZYH","");
        params.put("STATUS","");

        iExamDao.bill(params);
        return params;
    }

    @Override
    public List<Map<String,Object>> application(Map<String, Object> params) {
        List<Map<String,Object>> resList = iExamDao.application(params);
        return resList;
    }

    @Override
    public Map<String, Object> examResultReport(List<Map<String, Object>> reportList) {
        Assert.isTrue(reportList!=null && !reportList.isEmpty(),"返回报告数据为空.");
        Map<String, Object> res = new HashMap<>();
        for (Map<String, Object> el : reportList) {
            iExamDao.examResultReport(el);
            if (!"0".equals(el.get("ret"))){
                res.put("ret","-1");
                res.put("message","写入数据异常");
            }
        }
        res.put("ret","0");
        res.put("message","写入数据成功.");
       return res;
    }

    @Override
    public void modifyReport(Map<String, Object> params) {
        turtleExamDao.modify(params);
    }
}
